package com.pubinfo.passbook.common.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.pubinfo.passbook.common.model.dto.open.WiteoffRelateSupplier;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 报账单供应商表
 *
 * @TableName t_witeoff_relate_supplier
 */
@TableName(value = "t_witeoff_relate_supplier")
@Data
@NoArgsConstructor
@ApiModel(value = "TWiteoffRelateSupplier", description = "报账单供应商表,接收前端报账单数据")
public class TWiteoffRelateSupplier implements Serializable {
  /**
   *
   */
  @TableId(type = IdType.ASSIGN_UUID, value = "id")
  private String id;
  
  /**
   * 供应商编码	非必须	该处可传送总账科目、供应商、客户，通过科目类型区分主数据属性
   */
  @ApiModelProperty(value = "供应商编码 该处可传送总账科目、供应商、客户，通过科目类型区分主数据属性")
  private String supplierCode;
  
  /**
   * 供应商名称	非必须	该处可传送总账科目、供应商、客户，通过科目类型区分主数据属性
   */
  @ApiModelProperty(value = "供应商名称  非必须  该处可传送总账科目、供应商、客户，通过科目类型区分主数据属性")
  private String supplierName;
  
  /**
   * 科目类型	非必须	选输(1-总账、2-供应商、3-客户),有科目时必须
   */
  @ApiModelProperty(value = "科目类型  非必须  选输(1-总账、2-供应商、3-客户),有科目时必须")
  private Byte accountType;
  
  /**
   * 金额	非必须	价款(不含税)
   */
  @ApiModelProperty(value = "金额  非必须  价款(不含税)")
  private Double sum;
  
  /**
   * 进项税金额	必须	当“票据类型”为1、4、5、6、11时，进项税金额必须，
   */
  @ApiModelProperty(value = "进项税金额  必须  当“票据类型”为1、4、5、6、11时，进项税金额必须")
  private Double inputTaxSum;
  /**
   * 发票金额
   */
  @ApiModelProperty(value = "发票金额")
  private Double invoiceSum;
  
  /**
   * 是否挑对	非必须	总账科目挑对时，该relateSuppliers可同时存在总账科目跟供应商，isPicking为必填
   */
  @ApiModelProperty(value = "是否挑对  非必须  总账科目挑对时，该relateSuppliers可同时存在总账科目跟供应商，isPicking为必填")
  private Byte isPicking;
  
  /**
   * 报账单id
   */
  @ApiModelProperty(hidden = true)
  private String otherSystemMainId;
  
  @TableField(exist = false)
  private static final long serialVersionUID = 1L;
  
  public TWiteoffRelateSupplier(TMdmSupplier supplier, Double sum) {
    this.supplierCode = supplier.getLifnr();
    this.supplierName = supplier.getName1();
    this.accountType = 2;
    this.sum = sum;
    this.invoiceSum = sum;
  }
  
  
  public TWiteoffRelateSupplier(WiteoffRelateSupplier witeoffRelateSupplier, String otherSystemMainId) {
    BeanUtils.copyProperties(witeoffRelateSupplier, this);
    this.otherSystemMainId = otherSystemMainId;
  }
  
  public static List<TWiteoffRelateSupplier> toList(List<WiteoffRelateSupplier> witeoffRelateSuppliers, String otherSystemMainId) {
    if (CollectionUtils.isEmpty(witeoffRelateSuppliers)) {
      return null;
    }
    List<TWiteoffRelateSupplier> tWiteoffRelateSuppliers = new ArrayList<>();
    for (WiteoffRelateSupplier witeoffRelateSupplier : witeoffRelateSuppliers) {
      TWiteoffRelateSupplier tWiteoffRelateSupplier = new TWiteoffRelateSupplier(witeoffRelateSupplier, otherSystemMainId);
      tWiteoffRelateSuppliers.add(tWiteoffRelateSupplier);
    }
    return tWiteoffRelateSuppliers;
  }
}